var express = require('express');
var router = express.Router();
var query = require('./Database');

/* GET home page. */
router.get('/', function(req, res, next) {
    res.render('ProCollect', {});
});
router.post('/collect',async (req,res,next)=>{
    let froData = req.body;
    console.log("-----------------");
    console.log(froData);
    let rows = await query("select * from goods where userid = " + froData.userid +" and state = " +froData.state);
    console.log("++++++++++++++++");
    console.log(rows);
    let data = [{code:100},rows];
    // res.render(data);
    res.send(data);
    // res.sendFile(data);
})
router.post('/delcollect',async (req,res,next)=>{
    let froData = req.body;
    console.log("-----------------");
    console.log(froData);
    let rows = await query("update goods set state = 14 where userid = " + froData.userid +" and id = " +froData.id);
    console.log("++++++++++++++++");
    console.log(rows);
    let data = [{code:200}];
    // res.render(data);
    res.send(data);
    // res.sendFile(data);
})
module.exports = router;